package cst.a806yf.zyfypt_806yf.Fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cst.a806yf.zyfypt_806yf.Adapter.TwareAdapter;
import cst.a806yf.zyfypt_806yf.Linstener.AmicoolListener;
import cst.a806yf.zyfypt_806yf.Bean.TwareBean;
import cst.a806yf.zyfypt_806yf.R;
import cst.a806yf.zyfypt_806yf.Model.ResModel;

/**
 * Created by Neusoft on 2017/4/9.
 */



public class Fragment3 extends Fragment {
    private RecyclerView recyclerView;
    private TwareAdapter adapter;
    private RecyclerView.LayoutManager layoutManager;
    private AmicoolListener<List<TwareBean>> listener;
    private ResModel model;
    private List<TwareBean> list;
    private SharedPreferences sp;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View  view=inflater.inflate(R.layout.fragment_fragment_2,container,false);
        recyclerView=(RecyclerView)view.findViewById(R.id.rec_tware);
        adapter=new TwareAdapter(getActivity());
        list= new ArrayList<TwareBean>();
        layoutManager=new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);

        listener= new AmicoolListener<List<TwareBean>>() {
            @Override
            public void onResponse(List<TwareBean> l) {
                adapter.setList(l);
            }

            @Override
            public void onFail(String msg) {

            }
        };

        sp = getActivity().getSharedPreferences("ME", Context.MODE_APPEND);
        model = new ResModel("gson",sp.getString("session_id",""));
        model.getList("tware",1,listener);
        return view;
    }

    }
